import http from './http.js';

/* --===========================短信验证码--=========================== */
/**
 * 获取短信验证码
 * @param {{
 *  userCaptcha： 图形验证码
 *  userTel: 手机号
 * }} param 参数对象
 */
const getVerifyCode = async (param) => await http.post('/captcha/sendVerifyCode', param, { urlParam: true });

/* 图形验证码 */
const getCodeImage = async (param) => await http.get('/captcha/createCaptcha', param, {
  responseType: 'arraybuffer'
});

/* --===========================短信验证码-end-=========================== */

/* --===========================用户注册--=========================== */

/**
 * 用户注册接口
 * @param {{
 *  userSmsCode: 短信验证码
 *  userTel: 电话号码
 * }} param 参数对象
 */
const register = async (param) => await http.post('/register/regByUserTel', param, { urlParam: true });

/* --===========================用户注册-end-=========================== */

/* --===========================审批管理--=========================== */
/**
 * 获取管理员我的审批信息
 */
const getMyApproves = async param => await http.post('/approve/myApproves', param, { urlParam: true });

/**
 * 审批接口
 * @param {{
 *  action: 审批处理 2-转交 3-同意 4-拒绝
 *  applicationId: 申请id
 * }} param 参数对象
 */
const approve = async (param, key) => await http.post(`/approve/forApprove?sessionKey=${key}`, param);

/**
 * 查询子管理员
 * @param {{
 *  sessionKey
 * }} param 参数
 */
const getSubManagers = async param => await http.post('/approve/getSubManagers', param, { urlParam: true });

/* --===========================审批管理-end-=========================== */

/* --===========================申请管理--=========================== */
/**
 * 用餐申请
 * @param {{
    "drinks": "白酒",
    "intentionHotel": "string",
    "linkNum": "string",
    "mealNum": 0,
    "mealTime": "2021-06-12T12:00:27.290Z",
    "mealType": "string",
    "reception": "string",
    "remark": "string"
}} param 参数对象
 */
const applyMeal = async (param, sessionKey) => await http.post(`/application/meal?sessionKey=${sessionKey}`, param);

/**
 * 会议预约
 * @param {{
    "endTime": "2021-06-12T12:23:39.733Z",
    "laserPointer": "0",
    "meetingMembers": "string",
    "meetingNum": 0,
    "meetingRoom": "string",
    "multimedia": "0",
    "remark": "string",
    "startTime": "2021-06-12T12:23:39.733Z",
    "teaWaterOpt": "热茶"
}} param 参数对象
 */
const applyMeeting = async (param, sessionKey) => await http.post(`/application/meeting?sessionKey=${sessionKey}`, param, { noModal: true });

/**
 * 住宿申请
 * @param {{
    "checkIn": "string",
    "checkInLoc": "string",
    "checkInNum": 0,
    "checkInTime": "2021-06-12T12:25:17.138Z",
    "checkOutTime": "2021-06-12T12:25:17.138Z",
    "fruitSnack": "0",
    "roomsNum": 0
}} param 参数对象
 */
const applyRoom = async (param, sessionKey) => await http.post(`/application/room?sessionKey=${sessionKey}`, param);

/**
 * 用车申请
 * @param {{
    "carNum": 0,
    "carTime": "2021-06-12T12:26:08.454Z",
    "carType": "越野五座",
    "destinationPoint": "string",
    "memberList": "string",
    "startingPoint": "string"
}} param 参数对象
 */
const applyCar = async (param, sessionKey) => await http.post(`/application/car?sessionKey=${sessionKey}`, param);

/**
 * 物业服务申请
 * @param {{
    "commercialType": "string",
    "loc": "string",
    "time": "2021-06-12T12:26:49.361Z"
  }} param 参数对象
 */
const applyService = async (param, sessionKey) => await http.post(`/application/commercialService?sessionKey=${sessionKey}`, param);

/**
 * 查询意向商家
 */
const intentionBusiness = async param => await http.post('/application/intentionHotels', param, { urlParam: true });

/**
 * 查询我的预约列表
 */
const getMyApplications = async param => await http.post('/application/myApplications', param, { urlParam: true });

/**
 * 撤回、删除申请
 * @param {{
 *  applicationId: order id
 *  sessionKey
 * }} param 参数对象
 */
const revokeOrder = async param => await http.post('/application/revoke', param, { urlParam: true });

/**
 * 查询会议时信息
 * @param {{ sessionKey }} param 参数对象
 */
const getMeetingRooms = async param => await http.post('/application/getAllMeetingRoom', param, { urlParam: true });

/**
 * 查询申请详情
 * @param {{
 *  applicationId: 申请id
 *  sessionKey
 * }} param 参数对象
 */
const getOrderDetail = async param => await http.post('/application/myApplicationsDetails', param, { urlParam: true });

/* --===========================申请管理-end-=========================== */

/* --===========================留言管理--=========================== */
/**
 * 查询留言
 */
const getmessages = async (param, config) => await http.post('/liveMessage/getAllMessage', param, { noModal: true, urlParam: true, ...config });

/**
 * 发布留言
 * @param {string} message 刘亚内容
 */
const postMessage = async (param, key) => await http.post(`/liveMessage/postMessage?sessionKey=${key}`, param);

/* --===========================留言管理-end-=========================== */

/* --===========================项目动态--=========================== *//**
 * 查询所有项目动态
 */
const getProjections = async param => await http.post('/projectDynamics/getAllDynamics', param, { urlParam: true });


/* --===========================项目动态-end-=========================== */

/* --===========================用户登录管理--=========================== */
/**
 * 自定义登录
 * @param {String} jsCode 小程序登录获取的 code
 */
const login = async (jsCode = '') => await http.post('/login/userLogin', { jsCode }, {
  urlParam: true
});

/* --===========================用户登录管理-end-=========================== */

export default {
  getVerifyCode,
  getCodeImage,
  login,
  register,
  getMyApproves,
  approve,
  applyMeal,
  applyMeeting,
  applyRoom,
  applyCar,
  applyService,
  intentionBusiness,
  getMyApplications,
  getmessages,
  getProjections,
  postMessage,
  getSubManagers,
  revokeOrder,
  getMeetingRooms,
  getOrderDetail
};